const util = require("util");
module.exports = (err, req, res, next) => {
  console.log("出错啦", err);
  switch(err.name) {
    case "ValidationError":
      res.sendErr({
        code: 400,
        message: err.message,
      })
      break
    case "UnauthorizedError":
      res.sendErr({
        code: 401,
        message: err.message,
      })
      break
    default:
      res.sendErr({
        code: 500,
        message: util.format(err) || "未知错误",
      });
  }
};
